import math
from pycgtypes import vec3, mat3

# jiffy components to compute things: not really needed in general

r2d = 180.0 / math.pi
ex, ey, ez = vec3(1,0,0), vec3(0,1,0), vec3(0,0,1)

def kappaVector(alpha):
    return vec3([-1*math.sin(alpha), 0, math.cos(alpha)])

import os

if 'XOALIGN_CALIB' in os.environ:

    # take these settings from file pointed at from the environment

    import imp
    xoalign_calib = imp.load_source('calib', os.environ['XOALIGN_CALIB'])
    GONIOMETER_NAME = xoalign_calib.GONIOMETER_NAME
    GONIOMETER_AXES_NAMES = xoalign_calib.GONIOMETER_AXES_NAMES
    GONIOMETER_AXES = xoalign_calib.GONIOMETER_AXES
    GONIOMETER_DATUM = xoalign_calib.GONIOMETER_DATUM

elif 'XOALIGN_CALIB_JSON' in os.environ:

    # take these settings from file pointed at from the environment

    import json
    xoalign_calib = json.loads(open(os.environ['XOALIGN_CALIB_JSON']).read())
    GONIOMETER_NAME = xoalign_calib['GONIOMETER_NAME']
    GONIOMETER_AXES_NAMES = xoalign_calib['GONIOMETER_AXES_NAMES']
    GONIOMETER_AXES = xoalign_calib['GONIOMETER_AXES']
    GONIOMETER_DATUM = xoalign_calib['GONIOMETER_DATUM']

else:
    # use hard-coded values

    # -- DLS's MiniKappa Goniometer definitions --
    GONIOMETER_NAME = "DLS's MiniKappa"
    GONIOMETER_AXES_NAMES = ("Omega","Kappa","Phi")
    GONIOMETER_AXES = [ez, kappaVector(-24/r2d), ez]
    GONIOMETER_DATUM = (0,0,45)  # in degree

    # -- DLS's MiniKappa Goniometer definitions --
    GONIOMETER_NAME = "DLS's MiniKappa"
    GONIOMETER_AXES_NAMES = ("Omega","Kappa","Phi")
    GONIOMETER_AXES = [ez, kappaVector(-24/r2d), ez]
    GONIOMETER_DATUM = (0,0,45)  # in degree

if __name__ == '__main__':
    
    print 'GONIOMETER_NAME=', GONIOMETER_NAME
    print 'GONIOMETER_AXES_NAMES=', GONIOMETER_AXES_NAMES
    print 'GONIOMETER_AXES=', GONIOMETER_AXES
    print 'GONIOMETER_DATUM=', GONIOMETER_DATUM
    

